// Stuff that we need to reuse can go here

package edu.berkeley.drivingbuddy;

import java.util.ArrayList;

import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.content.Intent;

import android.util.Log;
import android.widget.Toast;

public class DrivingBuddy extends Application {

	private static Context mContext;
	private static Datastore mDatastore;

	public void onCreate() {
		mContext = getApplicationContext();
		mDatastore = new Datastore();
		fillWithFakeData();
	}

	public static Datastore getDatastore() {
		return mDatastore;
	}

	private static void fillWithFakeData() {
	//	// TODO: add random stuff to the datastore, if we want it
	//	// Here is our old fake data. it wouldn't work exactly but may be a starting point:
	//	// //////// MAKE FAKE DATA /////////
		 Datastore ds = DrivingBuddy.getDatastore();
		 //ResultGroup resultGroup1 = ds.queryForOrCreateResultGroup(new Location(""), new Location(""));
		 ResultGroup resultGroup1 = new ResultGroup(new Location(""), new Location(""));
		 ds.getResultGroups().add(resultGroup1);
		 resultGroup1.setName("Going to School");
		 ResultObj rG1Obj1 = new ResultObj(resultGroup1, 1, 50,null);
		 ResultObj rG1Obj2 = new ResultObj(resultGroup1, 2, 80,null);
		 ResultObj rG1Obj3 = new ResultObj(resultGroup1, 3, 76,null);
		 
		 resultGroup1.getResults().add(rG1Obj1); // should probably be done by sorting when done for real
		 resultGroup1.getResults().add(rG1Obj2);
		 resultGroup1.getResults().add(rG1Obj3);
		 ds.registerNewResult(rG1Obj1);
		 ds.registerNewResult(rG1Obj2);
		 ds.registerNewResult(rG1Obj3);
		 
		 ResultGroup resultGroup2 = new ResultGroup(new Location(""), new Location(""));
		 ds.getResultGroups().add(resultGroup2);
		 //ResultGroup resultGroup2 = ds.queryForOrCreateResultGroup(new Location(""), new Location(""));
         resultGroup2.setName("Going home");
         ResultObj rG2Obj1 = new ResultObj(resultGroup2, 1, 63,null);
         ResultObj rG2Obj2 = new ResultObj(resultGroup2, 2, 26,null);
         ResultObj rG2Obj3 = new ResultObj(resultGroup2, 3, 50,null);
         
         resultGroup2.getResults().add(rG2Obj1); // should probably be done by sorting when done for real
         resultGroup2.getResults().add(rG2Obj2);
         resultGroup2.getResults().add(rG2Obj3);
         ds.registerNewResult(rG2Obj1);
         ds.registerNewResult(rG2Obj2);
         ds.registerNewResult(rG2Obj3);
         
		 ResultGroup resultGroup3 = new ResultGroup(new Location(""), new Location(""));
		 ds.getResultGroups().add(resultGroup3);
         //ResultGroup resultGroup3 = ds.queryForOrCreateResultGroup(new Location(""), new Location(""));
         resultGroup3.setName("Going to work");
         ResultObj rG3Obj1 = new ResultObj(resultGroup3, 1, 20,null);
         ResultObj rG3Obj2 = new ResultObj(resultGroup3, 2, 60,null);
         
         resultGroup3.getResults().add(rG3Obj1); // should probably be done by sorting when done for real
         resultGroup3.getResults().add(rG3Obj2);
         ds.registerNewResult(rG3Obj1);
         ds.registerNewResult(rG3Obj2);
	}
	
	// backs out of everything and goes to the main screen
	public static void getMeOutOfHere() {
		Intent intent = new Intent(mContext, mainPage.class);
		intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		mContext.startActivity(intent);
	}

	public static void displayUserToast(String text) {
		Toast.makeText(mContext, text, Toast.LENGTH_SHORT).show();
	}
	
}
